package com.sms.controller;

import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sms.common.A;
import com.sms.pojo.Orders;
import com.sms.service.impl.OrdersServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
//通过ID搜索会员所有订单
@WebServlet("/MembersOrdersSearchById")
public class MembersOrdersSearchByIdController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int memberID=Integer.parseInt(req.getParameter("memberID"));

        OrdersServiceImpl service=new OrdersServiceImpl();
        QueryWrapper<Orders> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("memberID",memberID);
        List<Orders> moList = service.list(queryWrapper);
        service.getSqlSession().close();
        if (!moList.isEmpty()) {
            resp.getWriter().write(JSONUtil.toJsonStr(A.success("会员订单搜索成功", moList), JSONConfig.create().setDateFormat("yyyy-MM-dd")));
        } else {
            resp.getWriter().write(JSONUtil.toJsonStr(A.fail("会员订单搜索失败")));
        }
    }
}
